<?php

namespace App\Http\Controllers\Order;

use App\Http\Controllers\BaseController;
use App\Models\Order\Outboundorderwithpay;
use App\Models\Balance\Balance;
use Illuminate\Http\Request;

/**
 * 出库单其他费用
 */
class OutboundorderwithpayController extends BaseController
{
    /**
     * 列表
     */
    public function getlist(Request $request)
    {
        $memberinfo = $this->mangerinfo;
        $isgetall = $request->isgetall ?? 0;
        $list = Outboundorderwithpay::getList($request, $memberinfo, $isgetall);

        $customBalance = Balance::where('custom_id', $request['custom_id'])->first();
        if ($customBalance) {
            $customBalance = $customBalance->toArray();
            $balance = $customBalance['balance'];
        } else {
            $balance = 0;
        }
        $list['customBalance'] = $balance;
        if ($list['list']) foreach ($list['list'] as $key => $value) {
            $list['list'][$key]['total_weight'] = mathfuncweight('div', $value['total_weight'], 10000, 4);
            $list['list'][$key]['total_money'] = mathfuncmoney('div', $value['total_money'], 100, 2);
            $list['list'][$key]['money'] = mathfuncmoney('div', $value['money'], 100, 2);
            // foreach ($value['suborder'] as $k => $v) {
            //     $list['list'][$key]['suborder'][$k]['total_weight'] = mathfuncweight('div', $v['total_weight'], 10000, 4);
            //     $list['list'][$key]['suborder'][$k]['total_weight'] = mathfuncmoney('div', $v['total_weight'], 100, 2);
            //     // $list['list'][$key]['suborder'][$k]['weight'] = $v['weight'] / 10000;
            //     // $list['list'][$key]['suborder'][$k]['unit_price'] = $v['unit_price'] / 100;
            //     // $list['list'][$key]['suborder'][$k]['total'] = $v['total'] / 100;
            // }
        }
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
